<template>
  <div>
    <el-dialog
      :title="title"
      :width="width"
      show-close
      :model-value="show"
      :draggable="true"
      :close-on-click-modal="false"
      :before-close="close"
      class="cust-dialog"
      :showCancel="showCancel"
    >
      <div class="dialog-body">
        <slot> </slot>
      </div>

      <template #header>
        <div class="dialog-header">
          {{ title }}
        </div>
      </template>

      <template #footer>
        <div class="dialog-footer">
          <template v-if="buttons && buttons.length > 0 || showCancel">
            <el-button
              link
              @click="close"
            >
              取消
            </el-button>
            <el-button
              v-for="(btn, index) in buttons"
              :key="index"
              :type="btn.type"
              @click="btn.click"
            >
              {{ btn.text }}
            </el-button>
          </template>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
const props = defineProps({
  title: {
    type: String,
    default: "标题",
  },
  show: {
    type: Boolean,
    default: false,
  },
  showClose: {
    type: Boolean,
    default: true,
  },
  showCancel: {
    type: Boolean,
    default: true,
  },
  top: {
    type: String,
    default: "50px",
  },
  width: {
    type: String,
    default: "30%",
  },
  buttons: {
    type: Array,
  },
});

const emit = defineEmits();
const close = () => {
  emit("close");
}

</script>

<style scoped lang="scss">
.cust-dialog {
  border-top: 5px solid black;
  .dialog-header {
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
  }

  .dialog-body {
   
    min-height: 100px;
  }

  .dialog-footer {
    border-top: 1px solid #eee;
    padding-top: 5px;
    text-align: right;
  }
}
</style>